#ifndef DW_GRFFITI_SAMPLER_INL
#	define DW_GRFFITI_SAMPLER_INL

namespace dw {
	namespace graffiti {

inline Sampler::Sampler()
:	m_id(0)
{
	glGenSamplers(1, &m_id);
}

inline Sampler::Sampler(GLuint id)
:	m_id(id)
{
}

inline Sampler::~Sampler()
{
	if (isValid())
	{
		glDeleteSamplers(1, &m_id);
	}
}

inline void Sampler::setWrap(sampler::wrap::mode::modes s, sampler::wrap::mode::modes t, sampler::wrap::mode::modes r)
{
	dwAssert(isValid(), "Invalid call to setWrap");

	glSamplerParameteri(m_id, sampler::wrap::glAxis(sampler::wrap::axis::s), sampler::wrap::glMode(s));
	glSamplerParameteri(m_id, sampler::wrap::glAxis(sampler::wrap::axis::t), sampler::wrap::glMode(t));
	glSamplerParameteri(m_id, sampler::wrap::glAxis(sampler::wrap::axis::r), sampler::wrap::glMode(r));
}

inline void Sampler::setMinFilter(sampler::filter::element::modes element, sampler::filter::mipmap::modes mipmap)
{
	dwAssert(isValid(), "Invalid call to setWrap");

	glSamplerParameteri(m_id, GL_TEXTURE_MIN_FILTER, sampler::glFilter(element, mipmap));
}

inline void Sampler::setMagFilter(sampler::filter::element::modes element)
{
	dwAssert(isValid(), "Invalid call to setWrap");

	glSamplerParameteri(m_id, GL_TEXTURE_MAG_FILTER, sampler::glFilter(element, sampler::filter::mipmap::none));
}

inline void Sampler::setLod(dw::float32 min, dw::float32 max)
{
	dwAssert(isValid(), "Invalid call to setWrap");

	glSamplerParameterf(m_id, GL_TEXTURE_MIN_LOD, min);
	glSamplerParameterf(m_id, GL_TEXTURE_MIN_LOD, max);
}

inline void Sampler::setCompare(sampler::compare::mode::modes mode, sampler::compare::func::funcs func)
{
	dwAssert(isValid(), "Invalid call to setWrap");

	glSamplerParameteri(m_id, GL_TEXTURE_COMPARE_MODE, sampler::compare::glMode(mode));
	glSamplerParameteri(m_id, GL_TEXTURE_COMPARE_FUNC, sampler::compare::glFunc(func));
}

inline bool Sampler::isValid() const
{
	return m_id != 0;
}

	} // namespace graffiti
} // namespace dw

#endif //! DW_GRFFITI_SAMPLER_INL
